package com.fjec.base.controller;

import com.fjec.common.protocol.JsonResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.fjec.base.service.ISysAgreementService;

import javax.annotation.Resource;

/**
 * <p>
 * 006.协议表 前端控制器
 * </p>
 *
 * @author admin
 * @since 2020-08-31
 */
@RestController
@RequestMapping("/")
public class SysAgreementController {

    @Resource
    private ISysAgreementService service;

    /**
     * 根据id获取协议
     *
     * @param id
     * @return
     */
    @GetMapping("/y/agree/getById")
    public JsonResult getById(Long id) {
        return service.selectById(id);
    }

    /**
     * 保存协议
     *
     * @param code
     * @param content
     * @param ver
     * @return
     */
    @PostMapping("/y/agree/save/or/update")
    public JsonResult save(Long id, String code, String content, Integer ver, String title, Integer value) {
        if (id == null || id == 0) {
            return service.save(code, content, ver, title, value);
        } else {
            return service.update(id, code, content, ver, title, value);
        }
    }

    /**
     * 获取可用协议
     *
     * @param code 协议编码
     * @return
     */
    @GetMapping("/n/agree/getVaild")
    public JsonResult getVaildAgreement(String code) {
        return service.getAgreement(code, 1);
    }
}
